﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace ProgNetComponents.Design.Attributes
{
    /// <summary>
    /// Returns DesignerSerializationVisibility
    /// </summary>
    public class SerializationVisibilityByMethodAttribute : Attribute, IDynamicAttribute
    {
        /// <summary>
        /// Method name
        /// </summary>
        public string DesignerSerializationVisibilityMethod
        {
            get;
            set;
        }
        /// <summary>
        /// Creates SerializationVisibilityByMethodAttribute instance
        /// </summary>
        /// <param name="DesignerSerializationVisibilityMethod">Method name. Method should return DesignerSerializationVisibility</param>
        public SerializationVisibilityByMethodAttribute(string DesignerSerializationVisibilityMethod)
        {
            this.DesignerSerializationVisibilityMethod = DesignerSerializationVisibilityMethod;
        }
        /// <summary>
        /// Returns result of invoking DesignerSerializationVisibilityMethod method
        /// </summary>
        /// <param name="owner"></param>
        /// <returns></returns>
        public Attribute GetRealAttribute(object owner)
        {
            DesignerSerializationVisibility visibility = DesignerSerializationVisibility.Hidden.FromObject(owner.RunMethod(DesignerSerializationVisibilityMethod));
            return new DesignerSerializationVisibilityAttribute(visibility);
        }
    }
}